<template>
  <a-modal
    :visible="visible"
    title="创建 团队/企业"
    centered
    :width="400"
    @cancel="onClose"
    @ok="onSubmit"
    ok-text="创建"
	:zIndex="1002"
  >
    <div class="modal-content">
      <a-input v-model:value="name" placeholder="团队/企业 名称" />
    </div>
  </a-modal>
</template>

<script>
import {
  defineComponent,
  reactive,
  toRefs,
  computed,
  watch,
  toRaw,
  h,
  onBeforeUnmount,
  createVNode,
} from "vue";
import request from "../../common/utils/request";
import store from "../../store/index";
import { useRoute, useRouter } from "vue-router";
import utils from "../../common/utils/utils";
import { Modal, notification, message } from "ant-design-vue";
import {
  PlusOutlined,
  ExclamationCircleOutlined,
  CloseCircleFilled,
} from "@ant-design/icons-vue";
let loginTimer = null;
export default defineComponent({
  name: "AddTeam",
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    business: {
      type: Number,
      default: 0,
    }
  },

  setup(props, context) {
    const route = useRoute();
    const router = useRouter();
    const state = reactive({
      name: "",
    });

    const onClose = () => {
      context.emit("onClose");
    };

    const onSubmit = () => {
      if (!state.name || state.name == "") {
        message.error("请输入团队名称");
        return;
      }
      request
        .post("/work_ai", "/user/team", { name: state.name, is_business: props.business })
        .then((res) => {
          if (res.id) {
            message.success("创建成功");

            state.name = '';
            
            store.dispatch("SetTeamId", res.id).then(() => {
              context.emit("success");
            });
          }
        });
    };

    return {
      ...toRefs(state),
      onClose,
      onSubmit,
    };
  },
});
</script>

<style lang="less" scoped>
.modal-content {
}
</style>
